package com.demo.common;

import lombok.Data;
import lombok.experimental.Accessors;

// 统一返回结果类
@Data
@Accessors(chain = true)
public class Result<T> {


    private String message;

    private T data;


    private Integer code;

    public static <T> Result<T> success() {
        return new Result<T>().setCode(200).setMessage("操作成功");
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>().setCode(200).setMessage("操作成功").setData(data);
    }

    public static <T> Result<T> error(String message) {
        return new Result<T>().setCode(500).setMessage(message);
    }

    public static <T> Result<T> error(Integer code,String message) {
        return new Result<T>().setCode(code).setMessage(message);
    }
}
